package com.heima.article.listen;

import com.alibaba.fastjson.JSON;
import com.heima.article.service.ApArticleService;
import com.heima.common.constants.article.HotArticleConstants;
import com.heima.model.mess.app.ArticleVisitStreamMess;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @作者 itcast
 * @创建日期 2021/2/24 17:11
 **/
@Component
@Slf4j
public class ArticleIncrHandleListener {

    @Autowired
    ApArticleService apArticleService;
    @KafkaListener(topics = HotArticleConstants.HOT_ARTICLE_INCR_HANDLE_TOPIC)
    public void handMsg(String msgJson){
        log.info("接收到 流式处理后的 文章行为数据 ==> {}",msgJson);
        if(StringUtils.isNotBlank(msgJson)){
            ArticleVisitStreamMess articleVisitStreamMess = JSON.parseObject(msgJson,ArticleVisitStreamMess.class);
            apArticleService.updateApArticle(articleVisitStreamMess);
            log.info("成功 更新对应文章的热点值 ==> {}",articleVisitStreamMess.getArticleId());
        }
    }

}
